package com.example.crud;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyDbHelper extends SQLiteOpenHelper {
    public static final String TB_NAME = "person";
    public MyDbHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    //创建数据库
//
//（1）创建表时，必须先删除同名的表；
//            （2）字段id是主键(primary key)且自增长(autoincrement) ；
//            （3）name是varchar类型；
////            （4）age是int类型（整型）
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("drop table if exists "+TB_NAME);
        db.execSQL("create table person " +
                "( id integer primary key  autoincrement," +
                "name varchar, age integer)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
